The File IO class contains a set of useful methods for opening, reading, writing and closing files with complete error checking. The Progress Bar class is a window item that you can update to reflect the progress of reading, writing or any type of processing.
How to Use in Your Program
-------------------------
The File IO class can be selectively loaded into your file; the Read File and Write File methods in the Menu class are simply examples of how you might use the methods from that class.
The Progress Bar class is a subclass of Canvas which can be selectively loaded into your file; then when you are creating your own Progress window in the window editor, you can create an item of type Progress Bar. The Read File and Write File methods in class Menu contain examples of how you initalise and update the progress bar while doing any sort of processing. The main decision you have to make for your particular situation is what unit you will use to measure the progress of your task - e.g., number of bytes transferred, number of transactions processed.
CLASS: FileIO
• Open Read File
Uses the get-file and open primitives to display a dialog and open an existing file for reading. Checks return from open primitive for errors.
• Read Line
Uses the read-line primitive to read a line from a text file. Checks result for errors.
• Read Block
Uses the read primitive to read a block of the given size from the given file, then checks result for errors.
• Check Read Error
When reading files, results of noErr and eofErr are OK, but all others are displayed by calling the "get error message" method.
• Close File
Calls the close primitive and checks the result for errors.
• Open Write File
Calls the put-file, delete, create and open primitives to open a file for writing. Checks results of each call for errors.
• Write Line
Uses the write-line primitive to write a line to a text file. Checks result for errors.
• Write Block
Uses the write primitive to write a block of the given size to the given file, then checks result for errors.
• Check Write Error
When writing a file, any error except noErr gets displayed.
CLASS: Menu
• Enable Menu Item
Useful method that enables or disables a menu item of the given name in a menu of the given name.
• Read File
Executed when you select "Read File..." from the File menu. Opens and initialises the window with a Progress Bar, uses methods from the File IO class to read in a text file while updating the progress bar, then closes the file and removes the Progress Window.
• Write File
Executed when you select "Write File..." from the File menu. Opens and initalises the Progress Window, uses methods from the File IO class to write out a text file while updating the progress bar, then closes the file and removes the Progress Window.